<template>
  <div class="addinstall">
    <!-- 添加或修改公告对话框 -->
    <el-dialog title="设备启用" :visible.sync="$parent.openEnable" width="40%" append-to-body>

      <div class="center_dialog">
        <div v-if="EnableObject.equipmentBaseVo.image" style="margin-top:20px;margin-left:15%">
          <ImagePreview :src="EnableObject.equipmentBaseVo.image" :width="`90%`" :height="190"></ImagePreview>
          <!-- <el-image :src="EnableObject.equipmentBaseVo.image" style="width:100%;height:100%"></el-image> -->
        </div>
        <div v-if="rowObj">
          <h2>{{ rowObj.equipmentName }}</h2>
          <p>设备编号:<span>{{ rowObj.equipmentNum }}</span> </p>
          <p>资产编号:<span>{{ rowObj.assetNum }}</span></p>
          <p>品牌:<span>{{ rowObj.equipmentBaseVo && rowObj.equipmentBaseVo.brand }}</span></p>
          <p>规格型号:<span>{{ rowObj.equipmentBaseVo && rowObj.equipmentBaseVo.model }}</span></p>
          <p>所属部门:<span>{{ EnableObject.deptName }}</span></p>
        </div>
      </div>
      <el-form ref="form" :rules="rules" :model="form" label-width="80px">
        <div class="cent_dia">
          <el-form-item label="启用日期" prop="enabledDate">
            <el-date-picker value-format="yyyy-MM-dd" v-model="form.enabledDate" type="date" style="width:240px"
              placeholder="启用日期" />
          </el-form-item>
        </div>
      </el-form>
      <div align="center" slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">启用</el-button>
        <el-button @click="() => $parent.openEnable = false">取 消</el-button>
      </div>

    </el-dialog>
  </div>
</template>

<script>
import { getpartdiliedlist, putaccounttenable } from '@/api/equipment/equipment.js'
// import Upload from '@/components/upload/index.vue'
export default {
  name: 'enabledialog',
  props: ['EnableObject'],
  components: {
    // Upload
  },
  data () {
    return {
      rowObj: null,
      form: {
        enabledDate: this.EnableObject.enableTime || ''
      },
      rules: {
        enabledDate: { required: true, message: '必填', trigger: 'blur' },
      }

    }
  },
  computed: {
  },
  created () {
    this.getlist()
  },
  methods: {
    async getlist () {
      let res = await getpartdiliedlist(this.EnableObject.equipmentAccountId, 0)
      this.rowObj = res.data
    },
    submitForm () {
      this.$refs['form'].validate((valid) => {
        if (!valid) return
        let params = {
          equipmentAccountId: this.EnableObject.equipmentAccountId,
          userStatus: '1',
          enableTime: this.form.enabledDate
        }
        putaccounttenable(params).then(res => {
          if (res.code === 200) {
            this.$message.success(res.msg)
            this.$parent.openEnable = false
            this.$parent.getList()
          }
        })
      })


    }
  }
}
</script>

<style lang="scss" scoped>
.center_dialog {
  // text-align: center;
  width: 85%;
  margin: 0px auto;
  display: flex;
  flex-wrap: wrap;

  div {
    flex: 1;
    // display: flex;
    flex-direction: column;
    justify-content: space-evenly;

    h2 {
      margin-left: 20px;
    }

    p {
      margin-left: 20px;

      span {
        color: #999;
      }
    }
  }
}

.cent_dia {
  width: 65%;
  margin: 10px auto;
}

::v-deep .is-disabled {
  .el-input__inner {
    background-color: #fff;
    color: #000
  }
}
</style>
<style>
</style>